
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 0826
 * @Author : WangRuoyu 
 * @Date : 2023/5/20 14:50
 */

#include "iostream"

using namespace std;

const int N = 1e5 + 10;
int e[N];
int ne[N];
int head = -1;
int idx = 0;

void insert(int x) {
    e[idx] = x;
    ne[idx] = head;
    head = idx++;
}

void deleteK(int k) {
    ne[k] = ne[ne[k]];
}

void insertK(int k, int x) {
    e[idx] = x;
    ne[idx] = ne[k];
    ne[k] = idx++;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        char ch;
        int k, x;
        cin >> ch;
        if (ch == 'H') {
            scanf("%d", &x);
            insert(x);
        } else if (ch == 'D') {
            scanf("%d", &k);
            if (!k) head = ne[head];
            else deleteK(k - 1);
        } else if (ch == 'I') {
            scanf("%d %d", &k, &x);
            insertK(k - 1, x);
        }
    }
    for (int i = head; i != -1; i = ne[i]) {
        printf("%d ", e[i]);
    }
}